<template>
  <el-dialog
    :title="!dataForm.payId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="订单编号" prop="payDingId">
      <el-input v-model="dataForm.payDingId" placeholder="订单编号"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="payCreatetime">
      <el-input v-model="dataForm.payCreatetime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="支付时间" prop="payPaytime">
      <el-input v-model="dataForm.payPaytime" placeholder="支付时间"></el-input>
    </el-form-item>
    <el-form-item label="第三方流水号" prop="payThirdId">
      <el-input v-model="dataForm.payThirdId" placeholder="第三方流水号"></el-input>
    </el-form-item>
    <el-form-item label="支付状态(待支付，已支付，支付失败)" prop="payStatus">
      <el-input v-model="dataForm.payStatus" placeholder="支付状态(待支付，已支付，支付失败)"></el-input>
    </el-form-item>
    <el-form-item label="支付流水号" prop="payPaywaterId">
      <el-input v-model="dataForm.payPaywaterId" placeholder="支付流水号"></el-input>
    </el-form-item>
    <el-form-item label="第三方回调信息" prop="payThirdMessage">
      <el-input v-model="dataForm.payThirdMessage" placeholder="第三方回调信息"></el-input>
    </el-form-item>
    <el-form-item label="支付类型(chat,alipay)" prop="payPaytype">
      <el-input v-model="dataForm.payPaytype" placeholder="支付类型(chat,alipay)"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          payId: 0,
          payDingId: '',
          payCreatetime: '',
          payPaytime: '',
          payThirdId: '',
          payStatus: '',
          payPaywaterId: '',
          payThirdMessage: '',
          payPaytype: ''
        },
        dataRule: {
          payDingId: [
            { required: true, message: '订单编号不能为空', trigger: 'blur' }
          ],
          payCreatetime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          payPaytime: [
            { required: true, message: '支付时间不能为空', trigger: 'blur' }
          ],
          payThirdId: [
            { required: true, message: '第三方流水号不能为空', trigger: 'blur' }
          ],
          payStatus: [
            { required: true, message: '支付状态(待支付，已支付，支付失败)不能为空', trigger: 'blur' }
          ],
          payPaywaterId: [
            { required: true, message: '支付流水号不能为空', trigger: 'blur' }
          ],
          payThirdMessage: [
            { required: true, message: '第三方回调信息不能为空', trigger: 'blur' }
          ],
          payPaytype: [
            { required: true, message: '支付类型(chat,alipay)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.payId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.payId) {
            this.$http({
              url: this.$http.adornUrl(`/proprietary/payuser/info/${this.dataForm.payId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.payDingId = data.payUser.payDingId
                this.dataForm.payCreatetime = data.payUser.payCreatetime
                this.dataForm.payPaytime = data.payUser.payPaytime
                this.dataForm.payThirdId = data.payUser.payThirdId
                this.dataForm.payStatus = data.payUser.payStatus
                this.dataForm.payPaywaterId = data.payUser.payPaywaterId
                this.dataForm.payThirdMessage = data.payUser.payThirdMessage
                this.dataForm.payPaytype = data.payUser.payPaytype
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/proprietary/payuser/${!this.dataForm.payId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'payId': this.dataForm.payId || undefined,
                'payDingId': this.dataForm.payDingId,
                'payCreatetime': this.dataForm.payCreatetime,
                'payPaytime': this.dataForm.payPaytime,
                'payThirdId': this.dataForm.payThirdId,
                'payStatus': this.dataForm.payStatus,
                'payPaywaterId': this.dataForm.payPaywaterId,
                'payThirdMessage': this.dataForm.payThirdMessage,
                'payPaytype': this.dataForm.payPaytype
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
